<%@page import="com.situ.web.vo.PageInfo"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.situ.web.entity.Course"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<%@ include file="header.jsp"%>
	<meta charset="UTF-8">
	<title>Insert title here</title>
	<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
	<%-- ${list} --%>
	<table border="1" cellspacing="0" width="400px">
		<tr>
			<td>ID</td>
			<td>名字</td>
			<td>学分</td>
			<td>删除</td>
		</tr>
		<c:forEach items="${pageInfo.list}" var="course">
			<tr>
				<td>${course.id}</td>
				<td>${course.name}</td>
				<td>${course.credit}</td>
				<td><a href="javascript:void(0)" onclick="deleteById(${course.id})">删除</a></td>
			</tr>
		</c:forEach>
	</table>
	<nav aria-label="Page navigation">
	  <ul class="pagination">
	  	<!-- 上一页开始 -->
	  	<c:if test="${pageInfo.pageNo==1}">
		  	 <li class="disabled">
			      <a  href="#" aria-label="Previous">
			        <span aria-hidden="true">&laquo;</span>
			      </a>
		    </li>
	  	</c:if>
  		<c:if test="${pageInfo.pageNo!=1}">
		  	<li>
		      <a href="${path}/course?method=selectByPage&pageNo=${pageInfo.pageNo-1}" aria-label="Previous">
		        <span aria-hidden="true">&laquo;</span>
		      </a>
		    </li>
	  	</c:if>
	  	<!-- 上一页结束 -->
	  	<c:forEach begin="1" end="${pageInfo.totalPage}" var="i">
	  		<c:choose>
	  			<c:when test="${pageInfo.pageNo==i}">
	  				<li class="active"><a href="#">${i}</a></li>
	  			</c:when>
	  			<c:otherwise>
	  				 <li><a href="${path}/course?method=selectByPage&pageNo=${i}">${i}</a></li>
	  			</c:otherwise>
	  		</c:choose>
	  	</c:forEach>
	    <li>
	      <a href="#" aria-label="Next">
	        <span aria-hidden="true">&raquo;</span>
	      </a>
	    </li>
	  </ul>
	</nav>
	
	<script type="text/javascript">
		function deleteById(id) {
			<%-- 
			var isDelete = confirm('您确认要删除么？');
			if (isDelete) {
				location.href = '<%=request.getContextPath()%>/student?method=delete&id=' + id;
			} --%>
			
			// mylayer.confirm('您确定要删除么?', '${pageContext.request.contextPath}/student?method=delete&id=' + id);
			layer.confirm(
					'您确定要删除么？',
					{icon : 3},
					function(index){//点击确认触发
						$.post(
							'${path}/course?method=delete',
							{'id' : id},
							function(jsonObj) {
								// {msg: "删除成功", isSuccess: true}
								console.log(jsonObj);
								if (jsonObj.isSuccess) {
									mylayer.successMsg(jsonObj.msg);
									location.href = '${path}/course?method=selectByPage';
								} else {
									mylayer.errorMsg(jsonObj.msg);
								}
							},
							'json'
						);
						layer.close(index);
					}
				);
		}
	</script>
</body>
</html>